﻿using HSJM.Service.MWS.Application;
using HSJM.Service.MWS.Application.Models;
using HSJM.Service.MWS.Domain.Condition;
using HSJM.Service.MWS.Domain.Entitys;
using HSJM.Service.MWS.Filters;
using HSJM.Service.MWS.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace HSJM.Service.MWS.Controllers
{
    [WebApiTracker]
    [ApiExplorerSettings(GroupName = "Test")]
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        ITestService _testService { get; set; }
        public TestController(ITestService testService) {
            _testService = testService;
        }

        [Route("TestStr")]
        [HttpGet]
        public async Task<ActionResult> TestStr([FromQuery] long Id) {
            var result =await _testService.GetAsync(Id);
            return Ok(result);
        }

        [Route("TestList")]
        [HttpGet]
        public async Task<ActionResult> TestList([FromQuery] string  title)
        {
            //var result = await _testService.GetListAsync(new  { 
            //    Id = Id
            //}).ConfigureAwait(false);
            var result1 = await _testService.GetListAsync(new BaseTestCondition { 
                Title =title
            }).ConfigureAwait(false);
            return Ok(result1);
        }


        [Route("TestAdds")]
        [HttpGet]
        public async Task<ActionResult> TestAdd()
        {
            //var result = await packExportApp.InsertTest().ConfigureAwait(false);
            List<TestDto> tList = new List<TestDto>();
            for (int i = 0; i < 100; i++)
            {
                TestDto t = new TestDto();
                t.Title = i.ToString();
                tList.Add(t);
            }


           var result=  await _testService.InsertBatch(tList.MapToList<Test>());

            return Ok(result);
        }

        [Route("TesSW")]
        [HttpPost]
        public async Task<ActionResult> TesSW()
        {

            var result=  await _testService.InsertAsync(new Test
            {
                Title = "测试1231111111111111111111112222222222222222222222333333333333333333555555555555444444444444466666666666666777777777777777888888888888888899999999999777777777777777777777777777777",
            });
            return Ok(result);
        }

        [Route("TestDel")]
        [HttpPost]
        public async Task<ActionResult> TestDel([FromBody] TestDto dto)
        {
            var entity = await _testService.GetAsync(dto.Id.Value).ConfigureAwait(false);
            var result = await _testService.DeleteAsync(entity).ConfigureAwait(false);
            return Ok(result);
        }


        [Route("TestInsert")]
        [HttpPost]
        public async Task<ActionResult> TestInsert([FromBody] TestDto dto)
        {
            var result = await _testService.InsertAsync(new Test { 
                Title = dto.Title
            }).ConfigureAwait(false);
            return Ok(result);
        }
    }
}
